// import _ from 'lodash';
import * as types from '@/store/mutation-types';
import sendgetOrder from '@/request/order'; // 发送order的请求
import _ from 'lodash';
import router from '@/router';

export default {
  // 发送请求sendgetOrder
  async getOrderList({ commit, rootState }) {
    //* 显示loding
    commit(types.SHOW_LOADING);
    try {
      // console.log('rootState==>', rootState);
      const { user } = rootState.login; // rootState === store.state，拿到vuex里根目录的所有的state
      const userID = _.get(user, '_id');
      // console.log('userID==>', userID);
      // const userID = routState.user._id
      const result = await sendgetOrder(userID); // 从后台拿到全部的orderlist
      // console.log('result orderlist==>', result);

      commit(types.SET_LIST_HISTORY, { orderList: result.list }); // 放到vuex里面
    } catch (error) {
      console.log('error', error);
      commit(types.SHOW_ALERT, { message: error.message, func: () => { router.push('/login'); } });
    } finally {
      console.log('finally');
      // * 最终移除loading
      commit(types.HIDE_LOADING);
    }
  },

};
